/**
 * AduioListAdapter.java  [V 1.0.0]
 * classpath : com.example.learnservice.AduioListAdapter
 * zhangyw Create at 2015年4月11日 下午8:32:46
 */
package com.example.learnservice;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.text.format.DateFormat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * com.example.learnservice.AduioListAdapter
 * @author zhangyw
 * create at 2015年4月11日 下午8:32:46
 */
public class AduioListAdapter extends BaseAdapter{
  private static final String TAG = "AduioListAdapter";
  private List<File> data;
  private Context context;
  public AduioListAdapter(Context context,List<File> data){
    this.data=data;
    this.context=context;
  }
  /* (non-Javadoc)
   * @see android.widget.Adapter#getCount()
   */
  @Override
  public int getCount() {
    return data.size();
  }

  /* (non-Javadoc)
   * @see android.widget.Adapter#getItem(int)
   */
  @Override
  public Object getItem(int position) {
    return data.get(position);
  }

  /* (non-Javadoc)
   * @see android.widget.Adapter#getItemId(int)
   */
  @Override
  public long getItemId(int position) {
    return position;
  }
  
  private static class ViewHolder{
    TextView itemTitle;
    TextView itemDetail;
  }

  /* (non-Javadoc)
   * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
   */
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder =null;
    if(convertView==null){
      convertView=View.inflate(context, R.layout.item_list_view_music, null);
      holder = new ViewHolder();
      holder.itemTitle = (TextView) convertView.findViewById(R.id.item_title);
      holder.itemDetail=(TextView) convertView.findViewById(R.id.item_detail);
      convertView.setTag(holder);
    }else{
      holder=(ViewHolder) convertView.getTag();
    }
    holder.itemTitle.setText(data.get(position).getName());
    StringBuffer buffer = new StringBuffer();
    buffer.append(data.get(position).getPath());
    buffer.append("\n");
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    buffer.append(df.format(new Date(data.get(position).lastModified())));
    holder.itemDetail.setText(buffer.toString());
    return convertView;
  }
}
